package com.slipper.system.flow.controller;

import com.slipper.constants.FlowConstants;
import com.slipper.system.flow.bo.FlowLineBOs;
import com.slipper.system.flow.bo.FlowLineCondBO;
import com.slipper.system.flow.service.FlowLineCondService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.slipper.system.flow.bo.FlowLineBO;
import com.slipper.system.flow.service.FlowLineService;
import com.slipper.util.ResultUtil;

import java.util.List;

/**
 * 流程线路信息表
 */
@RestController
@RequestMapping("/system/flowLine")
public class FlowLineController {
    @Resource
    private FlowLineService flowLineService;
    @Resource
    private FlowLineCondService flowLineCondService;

    @PostMapping(value = "/queryBy")
    public String queryBy(@RequestBody FlowLineBO bo) {
        if(bo.getId() == null || "".equals(bo.getId())) {
            return ResultUtil.failureResult("数据获取失败！");
        }
        return ResultUtil.successResult(flowLineService.queryBy(bo.getId()));
    }
    
    @PostMapping(value = "/queryPage")
    public String queryPage(@RequestBody FlowLineBO bo) {
        return ResultUtil.successResult(flowLineService.queryPage(bo));
    }

    @PostMapping(value = "/save")
    public String save(@RequestBody FlowLineBO bo) {
        return ResultUtil.successResult(flowLineService.save(bo));
    }

    @PostMapping(value = "/delete")
    public String delete(@RequestBody FlowLineBO bo) {
        return ResultUtil.successResult(flowLineService.delete(bo));
    }

    @PostMapping(value = "/queryBranchList")
    public String queryBranchList(@RequestBody FlowLineBO bo) {
        bo.setPreNodeType(FlowConstants.FlowNode.TYPE_BRANCH);
        List<FlowLineBO> lineList = flowLineService.queryList(bo);
        lineList.forEach(line -> {
            FlowLineCondBO flowLineCondQO = new FlowLineCondBO();
            flowLineCondQO.setLineId(line.getId());
            line.setCondList(flowLineCondService.queryList(flowLineCondQO));
        });
        return ResultUtil.successResult(lineList);
    }

    @PostMapping("/saveLineCond")
    public String saveLineCond(@RequestBody FlowLineBOs bos) {
        return ResultUtil.saveResult(flowLineService.saveLineCond(bos));
    }
}
